<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-icon/iron-icon.html">
<!--<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">-->
<dom-module id="icon-login">
    <template>
        <style>
            :host {

            }
        </style>

        <h3>网络请求测试 </h3>
        <!--<iron-ajax-->
                <!--id="ajax"-->
                <!--handle-as="json"-->
                <!--content-type="application/json"-->
                <!--method="POST"-->
                <!--on-response="handleResponse"-->

                <!--debounce-duration="3000">-->
        <!--</iron-ajax>-->
        <input value="{{phone::input}}" placeholder="请输入手机">
        <input type="button" on-click="SMSTest" id="btn" value="{{smsText}}"  />
        <input value="{{phoneverify::input}}" placeholder="请输入手机验证码">
        <button  on-click="loginTest" raised>登录测试</button>
    </template>

</dom-module>

<script>
    Polymer({
        is: "icon-login",
        properties: {
            smsText: {
                type: String,

                value: "获取验证码"
            },
            phone: {
                type: String,

                value: ""
            },
            phoneerify: {
                type: String,
                value: ""
            },
            countdown: {
                type: Number,
                value: 60
            },
            baseUrl:{
                type:String,
                value:"http://192.168.31.200:8000/api/v1/"
            }

        },

        settime:function(){
            if (this.countdown == 0) {
                this.smsText="获取验证码";
                this.countdown = 60;
            } else {
                this.smsText="重新发送(" + this.countdown + ")";
                this.countdown--;
                setTimeout(function() {
                 this.settime() ;
                }.bind(this),1000)
            }
        },
        SMSTest:function () {

            // this.$.ajax.url = this.baseUrl+"sms/";
            // console.log(this.phone);
            // this.$.ajax.params={"phone":"13430196784"};
            //
            //
            //
            //
            // this.$.ajax.generateRequest();

            var xhr = new XMLHttpRequest();//发出去了 ,没有响应?

            if(xhr.readyState == 4 || xhr.status == 200){
                console.log(xhr.response, 11111111111111111111);
            }

            xhr.open( 'POST', 'http://192.168.31.200:8000/api/v1/sms/');
            var p = JSON.stringify({ phone: "13430196784"});
            xhr.setRequestHeader("Content-Type", "application/json")
            xhr.send(p)

            // this.settime();
        },
        loginTest:function () {

            var xhr = new XMLHttpRequest();//发出去了 ,没有响应?
            if(xhr.readyState == 4 || xhr.status == 200){
                console.log(xhr.response, 11111111111111111111);
            }
            xhr.open( 'POST', 'http://192.168.31.200:8000/api/v1/login/');
            var p = JSON.stringify({
                phone: "13430196784",
                phoneverify:this.phoneverify,
                client_id:"jc0JqCXdDKue4nposNYFo4w9IEDkZoXtSOgGGTby",
                client_secret:"pm6IeNuZD4LHxyJz6ee6SQZ9kTyhoOEYGr5HPPRcn53uZsIYWzwuFZE4sjwmhQIklYHZdkpCZIxoWKQV5hNavjoVFHMCcmFPrdmIUuYuFxO5wUpaOJ07IjwfqcAQBeOc",
                logintype:"2",
                grant_type:"password",
                }
             );
            xhr.send(p)
            console.log(this.phoneverify);

            // var formData = new FormData();
            // formData.append("phone", "13430196784");
            // formData.append("phoneverify",this.phoneverify);
            // formData.append("client_id", "jc0JqCXdDKue4nposNYFo4w9IEDkZoXtSOgGGTby");
            // formData.append("client_secret", "pm6IeNuZD4LHxyJz6ee6SQZ9kTyhoOEYGr5HPPRcn53uZsIYWzwuFZE4sjwmhQIklYHZdkpCZIxoWKQV5hNavjoVFHMCcmFPrdmIUuYuFxO5wUpaOJ07IjwfqcAQBeOc");
            // formData.append("logintype", "2");
            // formData.append("grant_type", "password");
            // // xhr.setRequestHeader("Content-Type", "application/json")
            // this.$.ajax.url = this.baseUrl+"login/";
            // this.$.ajax.body = formData;

            // this.$.ajax.generateRequest();
        },
        handleResponse: function(res) {
            var res = res.detail.response;
            console.log(res);
        }
        });

</script>

